package com.rfid.dao.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.rfid.dao.interfaces.CarreraDao;
import com.rfid.domain.Carrera;

@SuppressWarnings({"rawtypes","unchecked"})
@Repository
public class CarreraJdbc  implements  CarreraDao{
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<Carrera> listarCarreras(String codigo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Carrera> listarTodasCarreras() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Carrera obtenerCarrera(int idCarrera) throws SQLException {
			String Sql= "SELECT * FROM carrera WHERE idcarrera = ? LIMIT 1";
			List matches =jdbcTemplate.query(Sql, new Object[]{idCarrera}, new RowMapper(){

				@Override
				public Object mapRow(ResultSet rs, int rowNum)throws SQLException {
					Carrera carrera =new Carrera();
					carrera.setIdCarrera(rs.getInt("idcarrera"));
					carrera.setNombreCarrera(rs.getString("nombre_carrera"));
					carrera.setCodigoCarrera(rs.getString("codigo_carrera"));			
					return carrera;
				}
				
			});
			
		return  (matches.size() > 0 ? (Carrera) matches.get(0) : null);
	}
	

}
